
// Source File Name:   VersionInfo.java

package com.sunwayhorizo.health.hl7.common;

import java.io.PrintStream;
import java.io.PrintWriter;

import java.util.Enumeration;
import java.util.Vector;

public class VersionInfo
{

    public static final String RCS_ID = "$Header: VersionInfo.java 1.0 2006/11/27 22:06:09 mskees ship $";
    public static final String AOLJ_VERSION = new String("Applications Object Library, Core Java Roll Up Patch J");
    private static Vector mRCS_IDs = new Vector(500, 100);

    public static Vector getRCS_IDs()
    {
        return mRCS_IDs;
    }

    public static final boolean recordClassVersion(String s, String s1)
    {
        if(s != null)
        {
            mRCS_IDs.addElement(s1 + "#" + s);
            return true;
        } else
        {
            return false;
        }
    }

    public static final String recordVersion(String s, String s1)
    {
        if(s != null)
        {
            mRCS_IDs.addElement(s1 + "#" + s);
            return s;
        } else
        {
            return null;
        }
    }

    public static final boolean recordClassVersion(Class class1)
    {
        try
        {
            return recordVersion((String)class1.getField("RCS_ID").get(null), class1) != null;
        }
        catch(Exception _ex)
        {
            return false;
        }
    }

    public static final String recordVersion(String s, Class class1)
    {
        try
        {
            String s2 = class1.getName();
            int i = s2.lastIndexOf(".");
            String s1;
            if(i < 0)
                s1 = "";
            else
                s1 = s2.substring(0, i);
            if(recordClassVersion(s, s1))
                return s;
            else
                return null;
        }
        catch(Exception _ex)
        {
            return null;
        }
    }

    public static void printVersionInfo()
    {
        printVersionInfo(System.out);
    }

    public static void printVersionInfo(PrintStream printstream)
    {
        printVersionInfo(new PrintWriter(printstream));
    }

    public static void printVersionInfo(PrintWriter printwriter)
    {
        for(Enumeration enumeration = getPrettyVersionInfo(); enumeration.hasMoreElements(); printwriter.println(enumeration.nextElement()));
        printwriter.flush();
    }

    public static Enumeration getVersionInfo()
    {
        Enumeration enumeration = getRCS_IDs().elements();
        Vector vector = new Vector(getRCS_IDs().size());
        String s;
        int i;
        for(; enumeration.hasMoreElements(); vector.insertElementAt(s, i))
        {
            s = (String)enumeration.nextElement();
            i = 0;
            for(Enumeration enumeration1 = vector.elements(); enumeration1.hasMoreElements() && s.compareTo((String)enumeration1.nextElement()) > 0;)
                i++;

        }

        return vector.elements();
    }

    public static Enumeration getPrettyVersionInfo()
    {
        Enumeration enumeration = getVersionInfo();
        Vector vector = new Vector(getRCS_IDs().size(), 10);
        String s = "";
        String s3;
        for(; enumeration.hasMoreElements(); vector.insertElementAt(s3, vector.size()))
        {
            String s1 = (String)enumeration.nextElement();
            String s2 = s1.substring(0, s1.indexOf("#"));
            s3 = s1.substring(s1.indexOf("#") + 1);
            if(s2.compareTo(s) != 0)
            {
                s = s2;
                vector.insertElementAt(s2, vector.size());
            }
        }

        return vector.elements();
    }

    public static void displayClassVersion(String s)
    {
        displayClassVersion(s, System.out);
    }

    public static void displayClassVersion(String s, PrintStream printstream)
    {
        displayClassVersion(s, new PrintWriter(printstream));
    }

    public static void displayClassVersion(String s, PrintWriter printwriter)
    {
        try
        {
            printwriter.println(">>> Class: " + s);
            printwriter.println(Class.forName(s).getDeclaredField("RCS_ID").get(null));
        }
        catch(ClassNotFoundException _ex)
        {
            printwriter.println("Unable to find class " + s);
        }
        catch(NoSuchFieldException _ex)
        {
            printwriter.println("Class " + s + " does not have an RCS_ID field");
        }
        catch(SecurityException _ex)
        {
            printwriter.println("Security exception, unable to access field");
        }
        catch(IllegalAccessException _ex)
        {
            printwriter.println("IllegalAccessException, unable to access field");
        }
        catch(Exception exception)
        {
            exception.printStackTrace(printwriter);
        }
        printwriter.flush();
    }

    public static void AOLJ_RUP(String s)
    {
        System.out.println(AOLJ_VERSION);
        System.out.println("$Header: VersionInfo.java 115.11 2003/11/27 22:06:09 mskees ship $");
    }

    public static void main(String args[])
    {
        AOLJ_RUP(null);
        for(int i = 0; i < args.length; i++)
            displayClassVersion(args[i]);

    }

    public VersionInfo()
    {
    }

}
